package com.js.blog.result;

import com.js.blog.exception.IErrorCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author yanglin
 * @create 2024-02-28 15:52 星期三
 * description:
 */
@Data
public class ResponseEntity<T> {
    long code;//业务状态码
    
    String message;
    
    T data;
    
    public ResponseEntity(){}
    
    public ResponseEntity(long code,String message,T data){
        this.code = code;
        this.message = message;
        this.data = data;
    }
    
    public ResponseEntity(IErrorCode errorCode){
        this.code = errorCode.getCode();
        this.message = errorCode.getMessage();
        this.data = null;
    }


    /**
     * 成功
     * @return
     */
    public static ResponseEntity ok(){
        
        return new ResponseEntity<>(200,"成功",null);
    }
    
    public static ResponseEntity fail(){
        
        return new ResponseEntity(201,"失败",null);
    }
    
}
